# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

import pymysql
class VideoeduPipeline:
    def process_item(self, item, spider):
            DB_HOST = "127.0.0.1"
            DB_POST = 3306
            DB_USER = "root"
            DB_PASSWORD = "root"
            DB_NAME = "graduate-mysql"
            DB_CHART = "utf8"
            dbmy = pymysql.connect(
                host=DB_HOST,
                port=DB_POST,
                password=DB_PASSWORD,
                user=DB_USER,
                charset=DB_CHART,
                db=DB_NAME
            )
            # 操作模块
            cur = dbmy.cursor()
            sql = 'insert into videos(Title,Duration,Video_img,VideoID_category) values("{0}","{1}","{2}",5)'.format(item['Title'],item['Duration'],item['Video_img'])
            # # 执行sql语句
            print("------------------------------------------------------------------------------------------------------------------------------------")
            # print(item['title'])
            cur.execute(sql)
            # # 提交数据库
            dbmy.commit()
            # dbmy.close()
            return item
